﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MastePage/SubEmptyMaster.Master" AutoEventWireup="true" CodeBehind="QuoteAdd.aspx.cs" Inherits="BySoft.Web.Site.Order.QuoteAdd" %>

<%@ MasterType VirtualPath="~/MastePage/SubEmptyMaster.Master" %>
<%@ Register Assembly="OneSoft.Web" Namespace="OneSoft.Web.UI.WebControls" TagPrefix="asp" %>
<%@ Register Src="../UserControl/SuggestTextBox2.ascx" TagName="SuggestTextBox2"
    TagPrefix="uc1" %>
<%@ Register Assembly="BySoft.Web.Controls" Namespace="BySoft.Web.Controls" TagPrefix="cc1" %>
<asp:Content ID="cphHeadContent" runat="server" ContentPlaceHolderID="HeadPlace">
    <script language="javascript" type="text/javascript">
        $(function () {
            $("#tabs").tabs({ show: function (event, ui) { iframeAutoFit(); } });
        })
        function CheckTaxRate(obj) {
            if ($(obj).attr('checked')) {
                $("#<%=txtTaxRate.ClientID%>").val("17");
            } else {
                $("#<%=txtTaxRate.ClientID%>").val("");
            }
        }

    //客户
    function FunCustomer() {
        ShowTopDialog('选择客户', '../ComPage/QuerySCustomerByQuote.aspx', 'FillFile();', 1000, 600); return false;
    }
    function FillFile()
    {
        var str = getCookie(dialogReturn_key);
        if (str != null && str != "")
        {
            str = decodeURIComponent(str);
            var strs = str.split(',');
            if (undefined != strs[0]) {
                document.getElementById("<%=txtCustomerID.ClientID%>").value = strs[0];
            }
            if (undefined != strs[1]) {
                document.getElementById("<%=txtCustomerName.ClientID%>").value = strs[1];
            }
            if (undefined != strs[3]) {
                document.getElementById("<%=txtContactName.ClientID%>").value = strs[3];
            }
            if (undefined != strs[4]) {
                document.getElementById("<%=txtMobile.ClientID%>").value = strs[4];
            }

        }
            setCookie(dialogReturn_key, "");
    }

        function FunSendCustomer() {
            ShowTopDialog('选择送货公司', '../ComPage/QuerySCustomerByQuote.aspx', 'FillSend();', 1000, 600); return false;
        }
        function FillSend() {
            var str = getCookie(dialogReturn_key);
            if (str != null && str != "") {
                str = decodeURIComponent(str);
                var strs = str.split(',');
                if (undefined != strs[0]) {
                    document.getElementById("<%=hdSendCustomerID.ClientID%>").value = strs[0];
                }
                if (undefined != strs[1]) {
                    document.getElementById("<%=txtSendCustomerName.ClientID%>").value = strs[1];
                }
                if (undefined != strs[2]) {
                    document.getElementById("<%=txtAddr.ClientID%>").value = strs[2];
                }
                if (undefined != strs[3]) {
                    document.getElementById("<%=txtSendContactName.ClientID%>").value = strs[3];
                }
                if (undefined != strs[4]) {
                    document.getElementById("<%=txtSendMobile.ClientID%>").value = strs[4];
                }

            }
            setCookie(dialogReturn_key, "");
        }

        function FunAdd() {
            ShowTopDialog('添加明细', '../ComPage/QueryMProductByQuote.aspx', 'FillProess();', 1000, 600); return false;
        }
        function FillProess() {
            var str = getCookie(dialogReturn_key);
            if (str != null && str == "success") {
                $("#<%=btnHidden.ClientID %>").click();
            }
            setCookie(dialogReturn_key, "");
        }

        function CheckNumWithDotOne(txtBox) {
            if (txtBox != null && txtBox.value != "") {
                var numFormat = /(^[0-9]\d{0,9}(\.\d{0,4})?$)/;
                var text = txtBox.value;
                if (!numFormat.test(text)) {
                    txtBox.value = 0;
                }
            }
        }

        function ChangePriceAmount(obj) {
            var currency = $("#<%=ddlCurrency.ClientID%>").val();//币别
            var TaxRate = $("#<%=txtTaxRate.ClientID%>").val() * 1;//税率
            var strBase = "txtPrice";
            var pre = obj.id.replace(strBase, "");

            var dtxtNum = $("#" + pre + "txtNums").val() * 1;                    //输入的数量
            var dtxtPrice = $("#" + pre + "txtPrice").val() * 1;                 //输入的价格

            var dTax = 0;//税额
            var dAmount = 0;
            dAmount = dtxtPrice * dtxtNum;//金额 = 数量*人民币单价

            if (currency == "<%=BySoft.Server.Consts.CommonConsts.RMBCurrencyIndex%>") {
                if (TaxRate != 0) {
                    TaxRate = TaxRate / 100;
                }
                dTax = dAmount * TaxRate;
            }
            $("#" + pre + "txtAmount").val(dAmount.toFixed(2));
            $("#" + pre + "txtTax").val(dTax.toFixed(2));
        }

        function ChangeNumAmount(obj) {
            var currency = $("#<%=ddlCurrency.ClientID%>").val();//币别
            var TaxRate = $("#<%=txtTaxRate.ClientID%>").val() * 1;//税率
            var strBase = "txtNums";
            var pre = obj.id.replace(strBase, "");

            var dtxtNum = $("#" + pre + "txtNums").val() * 1;                    //输入的数量
            var dtxtPrice = $("#" + pre + "txtPrice").val() * 1;                 //输入的价格

            var dTax = 0;//税额
            var dAmount = 0;
            dAmount = dtxtPrice * dtxtNum;//金额 = 数量*人民币单价

            if (currency == "<%=BySoft.Server.Consts.CommonConsts.RMBCurrencyIndex%>") {
                if (TaxRate != 0) {
                    TaxRate = TaxRate / 100;
                }
                dTax = dAmount * TaxRate;
            }
            $("#" + pre + "txtAmount").val(dAmount.toFixed(2));
            $("#" + pre + "txtTax").val(dTax.toFixed(2));
        }

    </script>
    
    <style type="text/css">
        table {
            text-align: left;
        }
        #addPro {
            color:deepskyblue;
            height: 30px;
            line-height: 30px;
        }
        #addPro:hover {
            text-decoration:underline;
        }
    </style>
</asp:Content>
<asp:Content ID="cphContent" runat="server" ContentPlaceHolderID="EmptyMasteCPH">
    <h1 class="tit">订单管理 >> <a href="QuoteList.aspx">报价单</a> >> 新增</h1>
    <div class="tableStyle2">
        <asp:UpdatePanel ID="UpdatePanel3" runat="server">
            <ContentTemplate>
                <table cellpadding="0" cellspacing="0" id="tBase" runat="server">
                    <tr>
                        <th class="left2">报价单号码：</th>
                        <td class="right2"><asp:Label ID="lblQuoteID" CssClass="lblreadonly" runat="server"></asp:Label></td>
                        <th class="left2">日期：</th>
                        <td class="right2">
                            <input class="Wdate" id="cpBillDate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="true" runat="server" type="text"></input>
                        </td>
                    </tr>
                    <tr>
                        <th class="left2">客户编号：
                        </th>
                        <td class="right2">
                            <asp:TextBox CssClass="lblreadonly" ID="txtCustomerID" runat="server"></asp:TextBox>
                            <span style="color: Red">*</span>
                            <asp:RequiredFieldValidator ControlToValidate="txtCustomerID" ID="RequiredFieldValidator2" Display="None" runat="server" ErrorMessage="请选择客户" ValidationGroup="gSubmit"></asp:RequiredFieldValidator>
                            <a style="cursor: pointer;" onclick="FunCustomer()">
                                <img src="../App_Themes/Common_CSS/images/dot_14.gif" alt="" /></a>
                        </td>
                        <th class="left2">客户名称：
                        </th>
                        <td class="right2">
                            <asp:TextBox CssClass="lblreadonly" ID="txtCustomerName" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                     <tr>
                        <th class="left2">联系人：</th>
                        <td class="right2">
                            <asp:TextBox ID="txtContactName" runat="server" CssClass="fullHeight"></asp:TextBox>
                        </td>
                        <th class="left2">联系电话：</th>
                        <td class="right2">    
                            <asp:TextBox ID="txtMobile" runat="server" CssClass="fullHeight"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <th class="left2">送货公司：
                        </th>
                        <td class="right2">
                            <asp:TextBox CssClass="lblreadonly" ID="txtSendCustomerName" runat="server"></asp:TextBox>
                            <asp:HiddenField ID="hdSendCustomerID" runat="server" />
                            <span style="color: Red">*</span>
                            <asp:RequiredFieldValidator ControlToValidate="txtSendCustomerName" ID="RequiredFieldValidator1" Display="None" runat="server" ErrorMessage="请选择送货公司" ValidationGroup="gSubmit"></asp:RequiredFieldValidator>
                            <a style="cursor: pointer;" onclick="FunSendCustomer()">
                                <img src="../App_Themes/Common_CSS/images/dot_14.gif" alt="" /></a>
                        </td>
                        <th class="left2">送货地址：
                        </th>
                        <td class="right2">
                            <asp:TextBox CssClass="lblreadonly" ID="txtAddr" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                     <tr>
                        <th class="left2">送货人员：</th>
                        <td class="right2">
                            <asp:TextBox ID="txtSendContactName" runat="server" CssClass="fullHeight"></asp:TextBox>
                        </td>
                        <th class="left2">送货联系电话：</th>
                        <td class="right2">    
                            <asp:TextBox ID="txtSendMobile" runat="server" CssClass="fullHeight"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <th class="left2">币别：
                        </th>
                        <td class="right2">
                            <asp:DropDownList ID="ddlCurrency" runat="server" OnSelectedIndexChanged="ddlCurrency_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
                            <span style="color: Red">*</span>
                            <asp:RequiredFieldValidator ControlToValidate="ddlCurrency" ID="RequiredFieldValidator4" Display="None" runat="server" ErrorMessage="请选择币别" ValidationGroup="gSubmit"></asp:RequiredFieldValidator>
                        </td>
                        <th class="left2"></th>
                        <td class="right2"></td>
                    </tr>
                    <tr runat="server" id="TaxTr" style="display: none;">
                        <th class="left2">单价是否含税：
                        </th>
                        <td class="right2"><asp:CheckBox ID="chkIsTax" runat="server" onclick="CheckTaxRate(this)" /></td>
                        <th class="left2">税率：
                        </th>
                        <td class="right2">
                            <asp:TextBox ID="txtTaxRate" runat="server" onkeyup="CheckNumWithDotOne(this)"></asp:TextBox>%
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    <div class="tableStyle">
        <div id="tabs">
            <ul>
                <li><a href="#tabs-1">明细</a></li>
            </ul>
            <div id="tabs-1" class="tableStyle">
                <div style="width: 100%; padding-bottom: 10px">
                    <div align="right">
                        <a href="../MasteData/ProductList.aspx" id="addPro" target="_blank" title="新增产品资料">新增产品资料</a>
                        <label class="btnStylec png_bg">
                            <input type="button" value="新增" onclick="FunAdd()" />
                        </label>
                        <label class="btnStylec png_bg">
                            <asp:Button ID="btnHidden" runat="server" CssClass="Hidden" OnClick="btnHidden_Click" />
                        </label>
                    </div>
                </div>
                <div>
                    <asp:SGridView runat="server" ID="grdResult" Width="100%" ShowActionToolBar="false"
                        AutoGenerateColumns="false" AllowCascade="false" OnRowCommand="grdResult_RowCommand" OnRowDataBound="grdResult_RowDataBound">
                        <Columns>
                            <asp:TemplateField HeaderText="报价单明细编号" ItemStyle-CssClass="Hidden" FooterStyle-CssClass="Hidden" HeaderStyle-CssClass="Hidden">
                                <ItemTemplate>
                                    <asp:Label ID="lblQuoteDetailID" Text='<%#Eval("QuoteDetailID") %>' runat="server"></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="项次">
                                <ItemTemplate>
                                    <asp:Label ID="lblOrderNum" Text='<%#Eval("OrderNum") %>' runat="server"></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="产品编号">
                                <ItemTemplate>
                                    <asp:Label ID="lblProductID" Text='<%#Eval("ProductID") %>' runat="server"></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="产品名称">
                                <ItemTemplate>
                                    <asp:Label ID="lblProductName" Text='<%#Eval("ProductName") %>' runat="server"></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="单位">
                                <ItemTemplate>
                                    <asp:Label ID="lblUnit" Text='<%#Eval("Unit") %>' runat="server"></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="客户零件号">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtCustomerPartNo" Text='<%#Eval("CustomerPartNo") %>' runat="server" Width="80px"></asp:TextBox>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="数量">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtNums" Text='<%#Eval("Nums") %>' runat="server" onkeyup="CheckNumWithDotOne(this);ChangeNumAmount(this);" Width="80px"></asp:TextBox>
                                    <span style="color: Red">*</span>
                                    <asp:RequiredFieldValidator ControlToValidate="txtNums" ID="RequiredFieldValidator7" Display="None" runat="server" ErrorMessage="请输入数量！" ValidationGroup="gSubmit"></asp:RequiredFieldValidator>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="单价">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtPrice" Text='<%#Eval("Price") %>' runat="server" onkeyup="CheckNumWithDotOne(this);ChangePriceAmount(this);" Width="80px"></asp:TextBox>
                                    <span style="color: Red">*</span>
                                    <asp:RequiredFieldValidator ControlToValidate="txtPrice" ID="RequiredFieldValidator5" Display="None" runat="server" ErrorMessage="请输入单价！" ValidationGroup="gSubmit"></asp:RequiredFieldValidator>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="金额">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtAmount" Text='<%#Eval("Amount") %>' runat="server" CssClass="lblreadonly" Enabled="false" Width="80px"></asp:TextBox>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="税额">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtTax" Text='<%#Eval("Tax") %>' runat="server" CssClass="lblreadonly" Enabled="false" Width="80px"></asp:TextBox>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>
                                <HeaderStyle Width="35px" />
                                <HeaderTemplate>
                                    删除
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:ImageButton ImageUrl="../App_Themes/Common_CSS/images/delete_small.gif" runat="server"
                                        ID="ibtnDel" />
                                    <asp:Button ID="btnDel" runat="server" CssClass="Hidden" CommandArgument='<%#Eval("ProductID") %>'
                                        CommandName="del" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:SGridView>
                </div>
            </div>
        </div>
    </div>
    <div class="controlBar" align="center">
        <table cellpadding="0" cellspacing="0" style="width: 300px; margin: 0 auto;">
            <tr>
                <td colspan="4">
                    <label class="btnStyleb png_bg">
                        <asp:Button ID="btnSubmit" runat="server" Text="确定" ValidationGroup="gSubmit" OnClick="btnSubmit_Click" />
                    </label>
                    <label class="btnStylec png_bg">
                        <input type="button" id="Button2" value="返回" runat="server" onclick="window.location = 'QuoteList.aspx'" />
                    </label>
                </td>
            </tr>
        </table>
    </div>
</asp:Content>



